package net.wantongtech.xa.uploadbasicinfo.dao;

import com.wtkj.dao.impl.BaseDataTemplate;
import com.wtkj.vo.dzzf.base.qxsjz.entity.PortalTransOut;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理部中心总对总交易扣款数据DAO
 *
 * @author MaShibo
 * 日期 :  2020/2/6
 */
@Repository
public class ProcessCenterBankPayTransDataDao extends BaseDataTemplate {

    public List<String> queryAllCenterBankPayIntegratedTransOut() {
        final String sql =
                "SELECT tr.integratedid\n" +
                        "  FROM tr_integrated_transout tr\n" +
                        " WHERE EXISTS (SELECT 1\n" +
                        "          FROM tr_portal_transout t\n" +
                        "         WHERE t.integratedid = tr.integratedid\n" +
                        "           AND t.channelpushstate = 5)\n" +
                        "   AND tr.count <> 1";
        return jdbcTemplate.queryForList(sql, String.class);
    }


    public List<PortalTransOut> queryPortalTransOutByIntegratedId(String integratedId) {
        final String sql =
                "SELECT tr.*\n" +
                        "  FROM tr_portal_transout tr\n" +
                        " WHERE tr.integratedid = ?\n";
        return jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PortalTransOut.class), integratedId);
    }

    public int clearTransOutIntegratedInfo(String transactionId) {
        final String sql =
                " UPDATE tr_portal_transout tr\n" +
                        "    SET tr.integratedid = NULL, tr.isintegrated = 0\n" +
                        "  WHERE tr.transactionid = ?\n";
        return jdbcTemplate.update(sql, transactionId);
    }

}
